use std::thread;
use std::time::Duration;
use std::sync::mpsc;

#[derive(Debug)]
pub struct ThreadBase {}

pub fn thread_base_test() {
    let handle = thread::spawn(|| {
        for i in 1..10 {
            println!("The thread print value is {}", i);
            thread::sleep(Duration::from_millis(1));
        }
    });
    handle.join().unwrap();
    for i in 1..5 {
        println!("The main print value is {}", i);
        thread::sleep(Duration::from_millis(1));
    }
}

pub fn thread_message_test() {
    let (sx, rx) = mpsc::channel();
    thread::spawn(move || {
        let vals = vec![
            String::from("Hi,"),
            String::from("I "),
            String::from("am "),
            String::from("from "),
            String::from("thread!"),
        ];
        for val in vals {
            sx.send(val).unwrap();
            thread::sleep(Duration::from_millis(1));
        }
    });

    for rv in rx {
        print!("{}", rv);
    }
    println!(" ");
    println!("Finish......")
}